import hashlib
from _md5 import md5

from todo_api_project.base.mybase import Tools

class login_model(Tools):
    # 定义路径
    path = '/user/login'

    # 发送登录请求
    def login_action(self,usr,pwd,check='1234'):
        mydata = {
            "username": usr,
            "password": self.md5(text=pwd),
            "checkcode": check,
        }
        res = self.huihua.post(url=self.hosturl+self.path,data=mydata)
        return res.json()

    # def md5(self,text):
    #     """
    #     Md5加密 只能加密字符串
    #     :param text:  需要加密的内容，必须是个字符串
    #     :return:
    #     """
    #     m = hashlib.md5()  # 创建一个 md5加密工具
    #     m.update(str(text).encode(encoding='utf-8'))
    #     res = m.hexdigest()  # 生成加密后的内容
    #     return res



import requests
s = requests.session()
login = login_model(huihua=s)
msg = login.login_action(usr='ueuquu1342', pwd='afhahfhai34')
print(msg)